              package com.java.diagnostics.visualizer.parser.vgc.converters;
              
              import com.java.diagnostics.visualizer.data.axes.UnitConverterDefinition;
              import com.java.diagnostics.visualizer.impl.axes.UnitConverterDefinitionImpl;
              import com.java.diagnostics.visualizer.parser.vgc.constants.VGCAxes;
              
              public class EventUnitConverter extends EnumerationUnitConverter
              {
                public static final String BASEUNITS = VGCAxes.EVENTCODE;
                public static final String LABEL = VGCAxes.EVENT;
                public static final String UNITS = VGCAxes.EVENTUNITS;
              
                private static final UnitConverterDefinition definition = new UnitConverterDefinitionImpl(
                  BASEUNITS, LABEL, UNITS, false);
              
                public Event[] mapping = new Event[0];
                public int lastMapping;
              
                private void resizeMapping(int newLength)
                {
                  int newLen = Math.max(10, Math.max(newLength, this.mapping.length * 2));
                  Event[] tmp = new Event[newLen];
                  System.arraycopy(this.mapping, 0, tmp, 0, this.mapping.length);
                  this.mapping = tmp;
                }
              
                public int getValue(int constantValue, String label)
                {
                  if (constantValue >= this.mapping.length) {
                    resizeMapping(constantValue + 1);
                  }
                  if (this.mapping[constantValue] == null) {
                    this.mapping[constantValue] = new Event(++this.lastMapping, label);
                  }
                  return this.mapping[constantValue].value;
                }
              
                public String formatUnconverted(double number)
                {
                  int val = (int)Math.round(number);
                  for (int i = 0; i < this.mapping.length; i++) {
                    Event event = this.mapping[i];
                    if ((event != null) && (event.value == val)) {
                      return this.mapping[i].name;
                    }
                  }
                  return "";
                }
              
                public double parseUnconverted(String region)
                {
                  for (int i = 0; i < this.mapping.length; i++) {
                    if (this.mapping[i].name.equals(region)) {
                      return this.mapping[i].value;
                    }
                  }
                  return -1.0D;
                }
              
                public UnitConverterDefinition getDefinition()
                {
                  return definition;
                }
              
                public static class Event
                {
                  public final int value;
                  public final String name;
              
                  Event(int value, String name)
                  {
                    this.value = value;
                    this.name = name;
                  }
                }
              }

